/* $RCSFile: AddonNicePanesDesigner.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.Core/UI/Design/AddonNicePanesDesigner.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:29  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Reflection;
using System.Web.UI.Design;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AddonNice.UI.WebControls;

namespace AddonNice.UI.Design.WebControls
{
    /// <summary>
    /// AddonNicePanes design support class for Visual Studio.
    /// </summary>
	public class AddonNicePanesDesigner : ControlDesigner // CS 18/1/.07 TemplatedControlDesigner
	{
        TemplateGroupCollection col = null;

        /// <summary>
        /// Initialize components
        /// </summary>
        public override void Initialize(IComponent component)
        {
            // Initialize the base
            base.Initialize(component);
            // Turn on template editing
            SetViewFlags(ViewFlags.TemplateEditing, true);
        }

        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                if (col == null)
                {
                    // Get the base collection
                    col                         =   new TemplateGroupCollection();

                    // Create variables
                    // Get reference to the component as AddonNicePanes
                    AddonNicePanesBase ctl      =   (AddonNicePanesBase)Component;

                    // Create a TemplateGroup
                    TemplateGroup tempGroup     =   new TemplateGroup("Panes");
                    
                    // Create left pane TemplateDefinition
                    TemplateDefinition tempDef  =   new TemplateDefinition(this, "Left Pane", ctl, "LeftPaneTemplate", true);
                    tempGroup.AddTemplateDefinition(tempDef);
                    
                    // Create content pane TemplateDefinition
                    tempDef                     =   new TemplateDefinition(this, "Content Pane", ctl, "ContentPaneTemplate", true);
                    tempGroup.AddTemplateDefinition(tempDef);

                    // Create right pane TemplateDefinition
                    tempDef                     =   new TemplateDefinition(this, "Right Pane", ctl, "RightPaneTemplate", true);
                    tempGroup.AddTemplateDefinition(tempDef);
                    
                    col.Add(tempGroup);

                    // Create another TemplateGroup and populate it
                    tempGroup                   =   new TemplateGroup("Separators");
                    // Create Horizontal pane TemplateDefinition
                    tempDef                     =   new TemplateDefinition(this, "Horizontal Separator", ctl, "HorizontalSeparatorTemplate", true);
                    tempGroup.AddTemplateDefinition(tempDef);
                    
                    tempDef                     =   new TemplateDefinition(this, "Vertical Separator", ctl, "VerticalSeparatorTemplate", true);
                    tempGroup.AddTemplateDefinition(tempDef);

                    // Add the TemplateGroup to the TemplateGroupCollection
                    col.Add(tempGroup);
                }

                return col;
            }
        }

        /// <summary>
        /// Default constructor
        /// </summary>
		public AddonNicePanesDesigner() 
		{
		}

		/// <summary>
		/// Override the AllowResize property inherited
		/// from ControlDesigner to enable the control 
		/// to be resized. 
		/// It is recommended that controls allow resizing 
		/// when in template mode even if they normally 
		/// do not allow resizing. 
		/// </summary>
		public override bool AllowResize 
		{
			get 
			{
  			    return InTemplateMode;
			}
		}

        /*
		/// <summary>
		/// Override the GetCachedTemplateEditingVerbs method. 
		/// A control overrides this method to return the list 
		/// of template editing verbs applicable to the control. 
		/// </summary>
        /// <returns></returns>
        [System.Obsolete]
   		protected override TemplateEditingVerb[] GetCachedTemplateEditingVerbs() 
		{
			if (templateVerbsDirty)
			{
				DisposeTemplateVerbs();

				templateVerbs = new TemplateEditingVerb[2];
				templateVerbs[PaneTemplates] = new TemplateEditingVerb("PaneTemplates", PaneTemplates, this);
				templateVerbs[SeparatorTemplates] = new TemplateEditingVerb("SeparatorTemplates", SeparatorTemplates, this);
				templateVerbsDirty = false;
			}
			return templateVerbs;
		}
        */
        /*
		/// <summary>
		/// Override the CreateTemplateEditingFrame method. 
		/// This method takes a TemplateEditingVerb instance as an argument. 
		/// TemplateEditingVerb is a designer verb (a class that derives from DesignerVerb) 
		/// that enables the template editor to add a command to the control at design time. 
		/// </summary>
		/// <param name="verb"></param>
		/// <returns></returns>
        [System.Obsolete]
   		protected override ITemplateEditingFrame CreateTemplateEditingFrame(TemplateEditingVerb verb) 
		{
			ITemplateEditingService teService = (ITemplateEditingService) GetService(typeof(ITemplateEditingService));
			
			Trace.Assert(teService != null, "How did we get this far without an ITemplateEditingService?");
			Trace.Assert(verb.Index == 0 || verb.Index == SeparatorTemplates);

			string[] templateNames = null;
			System.Web.UI.WebControls.Style[] templateStyles = null;
			ITemplateEditingFrame editingFrame;
			System.Web.UI.WebControls.Style[] outputTemplateStyles;

			switch (verb.Index) 
			{
				case PaneTemplates:
					templateNames = AddonNicePanesDesigner.PaneTemplateNames;
					outputTemplateStyles = new Style[3];
					outputTemplateStyles[IDX_LEFT_PANE_TEMPLATE] = AddonNicePanes.LeftPaneStyle;
					outputTemplateStyles[IDX_CONTENT_PANE_TEMPLATE] = AddonNicePanes.ControlStyle;
					outputTemplateStyles[IDX_RIGHT_PANE_TEMPLATE] = AddonNicePanes.RightPaneStyle;
					templateStyles = outputTemplateStyles;
					break;
				case SeparatorTemplates:
					templateNames = AddonNicePanesDesigner.SeparatorTemplateNames;
					outputTemplateStyles = new Style[2];
					outputTemplateStyles[IDX_HORIZONTAL_SEPARATOR_TEMPLATE] = AddonNicePanes.HorizontalSeparatorStyle;
					outputTemplateStyles[IDX_VERTICAL_SEPARATOR_TEMPLATE] = AddonNicePanes.VerticalSeparatorStyle;
					templateStyles = outputTemplateStyles;
					break;
			}
			editingFrame = teService.CreateFrame(this, verb.Text, templateNames, AddonNicePanes.ControlStyle, templateStyles);
			//editingFrame = teService.CreateFrame(this, verb.Text, templateNames);
			return editingFrame;
		}
        */

        /*
		/// <summary>
		/// A type's Dispose method should release all the resources 
		/// that it owns. It should also release all resources owned 
		/// by its base types by calling its parent type's Dispose 
		/// method. 
		/// </summary>
		/// <param name="disposing"></param>
		protected override void Dispose(bool disposing) 
		{
			if (disposing) 
			{
				//DisposeTemplateVerbs();
				AddonNicePanes = null;
			}
			this.Dispose(disposing);
		}
        */

        /*
		private void DisposeTemplateVerbs() 
		{
			if (templateVerbs != null) 
			{
				for(int i = 0; i < templateVerbs.Length; i++) 
					templateVerbs[i].Dispose();

				templateVerbs = null;
				templateVerbsDirty = true;
			}
		}
        */

        
        // Add instructions to the placeholder view of the control
        public override string GetDesignTimeHtml()
        {
            return CreatePlaceHolderDesignTimeHtml("Click here and use the task menu to edit the templates.");
        }
        
        /*
        /// <summary>
		/// As with any other designer, override the GetDesignTimeHtml.
		/// Gets the HTML that is used to represent the control at design time.
		/// </summary>
		public override string GetDesignTimeHtml() 
		{
			StringBuilder designTimeHTML        =   new StringBuilder();
            // Get reference to the component as AddonNicePanesBase
            AddonNicePanesBase AddonNicePanes   =   (AddonNicePanesBase)Component;

		    designTimeHTML.Append("<table");
            if( !AddonNicePanes.Width.IsEmpty )
            {
		        designTimeHTML.Append(" width='");
		        designTimeHTML.Append(AddonNicePanes.Width.Value);
		        designTimeHTML.Append("'");
            }
            if( !AddonNicePanes.Height.IsEmpty )
            {
                designTimeHTML.Append(" height='");
                designTimeHTML.Append(AddonNicePanes.Height.Value);
                designTimeHTML.Append("'");
            }
		    designTimeHTML.Append(" border='1'>");
		    designTimeHTML.Append("<tr>");

		    designTimeHTML.Append("<td>");
			if (AddonNicePanes.VerticalSeparatorTemplate != null)
			{
                designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.VerticalSeparatorTemplate));
			}
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<td>");
			if (AddonNicePanes.LeftPaneTemplate != null)
			{
				//designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.LeftPaneTemplate));
			}
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<td>");
			if (AddonNicePanes.VerticalSeparatorTemplate != null)
			{
				//designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.VerticalSeparatorTemplate));
			}
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<td>");
            if (AddonNicePanes.ContentPaneTemplate != null)
            {
                //designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.ContentPaneTemplate));
            }
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<td>");
			if (AddonNicePanes.VerticalSeparatorTemplate != null)
			{
				//designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.VerticalSeparatorTemplate));
			}
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<td>");
            if (AddonNicePanes.RightPaneTemplate != null)
            {
                //designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.RightPaneTemplate));
            }
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("<TD>");
			if (AddonNicePanes.VerticalSeparatorTemplate != null)
			{
				//designTimeHTML.Append(GetTextFromTemplate(AddonNicePanes.VerticalSeparatorTemplate));
			}
		    designTimeHTML.Append("</td>");

		    designTimeHTML.Append("</tr>");
		    designTimeHTML.Append("</table>");

			return designTimeHTML.ToString();
		}
        */
		/// <summary>
		/// As with any other designer, 
		/// override the GetEmptyDesignTimeHtml.
		/// Gets the HTML used to represent 
		/// an empty template-based control at design time.
		/// </summary>
		protected override string GetEmptyDesignTimeHtml() 
		{
            return CreatePlaceHolderDesignTimeHtml("Click here and use the task menu to edit the templates.");
        }

        /*
		/// <summary>
		/// Override the GetTemplateContent method that gets 
		/// the template content. 
		/// </summary>
        [System.Obsolete]
   		public override string GetTemplateContent(ITemplateEditingFrame editingFrame, string templateName, out bool allowEditing) 
		{
			Trace.Assert(editingFrame.Verb.Index >= 0 && editingFrame.Verb.Index <= 2);

            allowEditing = true;
			ITemplate template = null;
			string templateContent = String.Empty;

			switch (editingFrame.Verb.Index) 
			{
				case PaneTemplates:
					if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_LEFT_PANE_TEMPLATE])
					{
						template = AddonNicePanes.LeftPaneTemplate;
						break;
					}
					if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_CONTENT_PANE_TEMPLATE])
					{
						template = AddonNicePanes.ContentPaneTemplate;
						break;
					}
					if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_RIGHT_PANE_TEMPLATE])
					{
						template = AddonNicePanes.RightPaneTemplate;
						break;
					}
					break;

				case SeparatorTemplates:
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_HORIZONTAL_SEPARATOR_TEMPLATE])
                    {
                        template = AddonNicePanes.HorizontalSeparatorTemplate;
                        break;
                    }
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_VERTICAL_SEPARATOR_TEMPLATE])
                    {
                        template = AddonNicePanes.VerticalSeparatorTemplate;
                        break;
                    }
                    break;
			}
			if (template != null)
				templateContent = GetTextFromTemplate(template);
			return templateContent;
		}
        */

        /*
		/// <summary>
		/// Override the SetTemplateContent method that sets 
		/// the template content. 
		/// </summary>
        [System.Obsolete]
   		public override void SetTemplateContent(ITemplateEditingFrame editingFrame, string templateName, string templateContent) 
		{
			Trace.Assert(editingFrame.Verb.Index >= 0 && editingFrame.Verb.Index <= 2);

			ITemplate template = null;

			if (templateContent != null && templateContent.Length != 0) 
			{
				template = GetTemplateFromText(templateContent);
			}

			switch (editingFrame.Verb.Index) 
			{
				case PaneTemplates:
					if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_LEFT_PANE_TEMPLATE]) 
					{
						AddonNicePanes.LeftPaneTemplate = template;
						return;
					}
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_CONTENT_PANE_TEMPLATE]) 
                    {
                        AddonNicePanes.ContentPaneTemplate = template;
                        return;
                    }
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_RIGHT_PANE_TEMPLATE]) 
                    {
                        AddonNicePanes.RightPaneTemplate = template;
                        return;
                    }
                    break;
				case SeparatorTemplates:
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_HORIZONTAL_SEPARATOR_TEMPLATE]) 
                    {
                        AddonNicePanes.HorizontalSeparatorTemplate = template;
                        return;
                    }
                    if (templateName == AddonNicePanesDesigner.PaneTemplateNames[IDX_VERTICAL_SEPARATOR_TEMPLATE]) 
                    {
                        AddonNicePanes.VerticalSeparatorTemplate = template;
                        return;
                    }
					return;

				default:
					return;
			}
		}
         */
	}
}